package br.com.viewcar.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Type;

import com.vividsolutions.jts.geom.Point;

@Entity
@Table(name = "PONTO", schema = "CHECKROTA")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@NamedQueries({
	@NamedQuery(name = "Ponto.findByCliente", query = "SELECT p FROM Ponto p WHERE p.cliente.id = ? AND p.status = 1"),
})
public class Ponto implements Serializable {

	private static final long serialVersionUID = 1313916916086964373L;

	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="SEQ_PONTO", nullable = false)
    private Integer id;

    @Column(name="DSC_PONTO", nullable = false, length = 50)
	private String nome;

	@Column(name="STA_PONTO", nullable = false)
	private Boolean status;

    @Column(name = "GEO_PONTO", nullable = false)
    @Type(type="org.hibernatespatial.GeometryUserType")
    private Point geometry;

	@ManyToOne
	@JoinColumn(name="SEQ_CLIENTE")
	private Cliente cliente;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public Boolean getStatus() {
		return status;
	}

	public void setStatus(Boolean status) {
		this.status = status;
	}

	public Point getGeometry() {
		return geometry;
	}

	public void setGeometry(Point geometry) {
		this.geometry = geometry;
	}

	public Cliente getCliente() {
		return cliente;
	}

	public void setCliente(Cliente cliente) {
		this.cliente = cliente;
	}

	public int hashCode() {

		int result = 1;
		result = 31 * result + ((id == null) ? 0 : id.hashCode());
		result = 31 * result + ((nome == null) ? 0 : nome.hashCode());

		return result;
	}

	public boolean equals(Object obj) {

		if (this == obj)
			return true;

		if (obj == null)
			return false;

		if (getClass() != obj.getClass())
			return false;

		Ponto other = (Ponto) obj;

		return ((id == null && other.id == null) || (id != null && id.equals(other.id))) &&
			((nome == null && other.nome == null) || (nome != null && nome.equals(other.nome)));
	}
}